home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / forms / searchst / findrplc.bas < prev    next >
Encoding:
BASIC Source File  |  1994-11-21  |  1.9 KB  |  63 lines

  1. 'used to figure out if it was a text box control passed to the function
  2. Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  3.  
  4. 'the class type of a VB Text Box
  5. Global Const TEXT_BOX = "ThunderTextBox"
  6.  
  7. 'variable to globalize the control we're searching and replacing
  8. Global FAndRControl As Control
  9.  
  10. 'constant to identify the FindandReplace form
  11. Global Const FIND_FORM_TAG = "FindFormTag"
  12.  
  13. 'message box constants
  14. Global Const MB_QUESTION = 36
  15. Global Const MB_YES = 6
  16.  
  17. Sub FindAndReplace (MyControl As Control)
  18.  
  19. Dim ClassName As String
  20. Dim RetVal As Integer
  21. Dim Looper As Integer
  22.  
  23. 'go through each form to see if the Find and Replace form is already loaded
  24. For Looper = 0 To Forms.Count - 1
  25.   If Forms(Looper).Tag = FIND_FORM_TAG Then Exit Sub
  26. Next Looper
  27.  
  28. 'clear out variable
  29. ClassName = String$(256, 0)
  30.  
  31. 'get the class name of the control to make sure that it's a VB Text Box
  32. RetVal = GetClassName(MyControl.hWnd, ClassName, 255)
  33.  
  34. ClassName = Left$(ClassName, RetVal)
  35.  
  36. If ClassName <> TEXT_BOX Then  'if we haven't been passed a text box as a control
  37.   MsgBox "The control you are checking is not a text box; the Search and Replace will not work.", 16, ProgTitle
  38.   Exit Sub
  39. End If
  40.  
  41. 'turn the pointer to an hourglass
  42. Screen.MousePointer = 11
  43.  
  44. 'set the global search and replace control variable
  45. Set FAndRControl = MyControl
  46.  
  47. 'if the text selection point isn't at the beginning, and no text is selected,
  48. 'ask the user if it should be moved there
  49. If (FAndRControl.SelStart > 0) And (FAndRControl.SelLength = 0) Then
  50.   If MsgBox("Do you want to start at the beginning of the text?", MB_QUESTION, ProgTitle) = MB_YES Then
  51.     FAndRControl.SelStart = 0
  52.   End If
  53. End If
  54.  
  55. 'show the search form
  56. FindForm.Show
  57.  
  58. 'turn the pointer back to normal
  59. Screen.MousePointer = 0
  60.  
  61. End Sub
  62.  
  63.